<%--
  Created by IntelliJ IDEA.
  User: ZhuChunXiao
  Date: 2017/5/25
  Time: 15:51
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
  String _id=request.getParameter("_");
%>

<div class="row">
  <div class="col-lg-12">
    <div class="panel">
      <div class="panel-heading header">
        <h3 class="panel-title" id="title">培训登记表</h3>
      </div>

      <!-- BASIC FORM ELEMENTS -->
      <!--===================================================-->
      <form id="form_train_input" class="panel-body form-horizontal form-padding">
        <input type="hidden" name="keyId" id="keyId" value="${train.id}" />
        <input type="hidden" name="curDutyId" id="curDutyId" value=""/>

        <div class="form-group">
          <label class="col-md-2 control-label">培训主题<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input type="text" id="theme" name="theme" class="form-control" placeholder="请输入培训主题" value="${train.theme}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">培训类型<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <select id="trainDictItemId" name="trainDictItemId" class="form-control">
              <option></option>
              <c:forEach var="item" items="${trainDictItems}" varStatus="status">
                <option value="${item.id}" <c:if test="${item.id == train.type.id}"> selected="selected"</c:if>>${item.name}</option>
              </c:forEach>
            </select>
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">培训内容<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input type="text" id="content" name="content" class="form-control" placeholder="请输入培训内容" value="${train.content}">
          </div>
        </div>

        <div class="form-group div-Hidden">
          <label class="col-md-2 control-label">培训开始日期<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-2">
            <div class="input-group date">
              <input type="text" class="form-control" id="cycleStart" name="cycleStart" placeholder="请选择培训开始日期"
                     value=<fmt:formatDate pattern="yyyy-MM-dd" value="${train.cycleStart}" /> >
              <span class="input-group-addon"><i class="ti-calendar"></i></span>
            </div>
          </div>
          <label class="col-md-2 control-label">培训结束日期<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-2">
            <div class="input-group date">
              <input type="text" class="form-control" id="cycleEnd" name="cycleEnd" placeholder="请选择培训结束日期"
                     value=<fmt:formatDate pattern="yyyy-MM-dd" value="${train.cycleEnd}" /> >
              <span class="input-group-addon"><i class="ti-calendar"></i></span>
            </div>
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">培训讲师<i class="fa fa-asterisk txt-color-red"></i></label>
          <div class="col-md-6">
            <input type="text" id="lecturer" name="lecturer" class="form-control" placeholder="请输入培训讲师" value="${train.lecturer}">
          </div>
        </div>

        <div class="form-group">
          <label class="col-md-2 control-label">
            <a href="javascript:void(0);" onclick="fn_members_dialog_select()" style="color: #0a6dbd">参与人员</a>
            <i class="fa fa-asterisk txt-color-red"></i>
          </label>
          <div class="col-md-6">
            <input type="text" id="userNames" name="userNames" class="form-control" placeholder="请选择参与人员"
                   value="<c:forEach var="item" items="${train.joinUsers}" varStatus="status">${item.name}<c:if test="${!status.last}">,</c:if></c:forEach>">
            <input type="hidden" id="userIds" name="userIds"
                   value="<c:forEach var="item" items="${train.joinUsers}" varStatus="status">${item.id}<c:if test="${!status.last}">,</c:if></c:forEach>">
          </div>
        </div>


        <div class="form-group">
          <label class="col-md-2 control-label">提交人</label>
          <div class="col-md-2">
            <p class="form-control-static">${train.creater.name}</p>
          </div>
          <label class="col-md-2 control-label">提交日期</label>
          <div class="col-md-2">
            <p class="form-control-static"><fmt:formatDate pattern="yyyy-MM-dd" value="${train.createTime}" /></p>
          </div>
        </div>

        <div class="panel-footer">
          <a class="btn btn-default" id="apply-re-common" href="javascript:void(0)">
            <i class="fa fa-lg fa-mail-reply"></i> 返回
          </a>
          <a class="btn btn-success" id="btn-save-common" href="javascript:void(0);"><i class="fa fa-lg fa-download"></i> 保存 </a>
          <c:if test="${train==null || train.processState=='Draft'}">
            <a class="btn btn-warning" id="btn-commit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 提交 </a>
          </c:if>
          <c:if test="${train!=null && train.processState=='Backed'}">
            <a class="btn btn-warning" id="btn-recommit-common" href="javascript:void(0);"><i class="fa fa-upload"></i> 再提交 </a>
          </c:if>
        </div>
        
      </form>
      <!--===================================================-->
      <!-- END BASIC FORM ELEMENTS -->
      
    </div>
  </div>
</div>

<script>
  var index = "${index}";
  var todo = "${todo}";
  var remind = "${remind}";
  var record = "${record}";
  var draft =  "${draft}";

  $(function(){
    var pdata= {
      keyId:$("#keyId").val(),
      entityName:"com.fz.us.oa.core.entity.com.Train"
    };
    multiDuty(pdata);
  });

  // 日期选择
  $('.input-group.date').datepicker({
    format: 'yyyy-mm-dd',
    weekStart: 1,
    autoclose: true,
    todayBtn: 'linked',
    todayHighlight: true,
    language: 'zh-CN'
  });

  // 字典列表下拉框
  $("#trainDictItemId").select2({
    placeholder: "请选择一个培训类型",
    allowClear: true
  });

  function fn_members_dialog_select() {
    __open_dialog_select('选择成员', '<%=path%>/main/member/dialogs?sids='+$("#userIds").val(), function (dialogRef) {
      var callback = function (data) {
        if (data) {
          dialogRef.close();
          // 获取 user
          $('#userIds').val(data.ids);
          $('#userNames').val(data.names)
        } else {
          dialogRef.enableButtons();
        }
      };
      fn_dialog_members_select(callback);
    });
  }

  //校验
  function infoValidate() {
    var tmp = "";

    tmp = $("input#theme").val();
    if(!tmp){
      __toastr_error("请输入培训主题！");
      return false;
    }

    tmp = $("select#trainDictItemId").val();
    if(!tmp){
      __toastr_error("请选择培训类型！");
      return false;
    }

    tmp = $("input#content").val();
    if(!tmp){
      __toastr_error("请输入培训内容！");
      return false;
    }

    tmp = $("input#cycleStart").val();
    if(!tmp){
      __toastr_error("请输入培训开始日期！");
      return false;
    }

    tmp = $("input#cycleEnd").val();
    if(!tmp){
      __toastr_error("请输入结束开始日期！");
      return false;
    }

    tmp = $("input#lecturer").val();
    if(!tmp){
      __toastr_error("请输入培训讲师！");
      return false;
    }

    tmp = $("input#userIds").val();
    if(!tmp){
      __toastr_error("请选择参与人员！");
      return false;
    }

    return true;
  }


  //保存
  $("#btn-save-common").click(
          function(e) {
            __confirm_dialog("提示：","确定保存吗？",
                    function () {
                      __form_save("form_train_input", "<%=path%>/com/train/save",function(){
                        $("#apply-re-common").trigger("click");
                      });
                    }
            )
          }
  );

  //提交
  $("#btn-commit-common,#btn-recommit-common").click(
          function(e) {
            var $valid = infoValidate();
//                console.log("v:"+$valid);
            if(!$valid) return false;

            __confirm_dialog("提示：","提交后填写资料不得修改，请确认是否进行提交？",
                    function () {
                      __form_save("form_train_input", "<%=path%>/com/train/submit",function(){
                        $("#apply-re-common").trigger("click");
                      });
                    }
            )
          }
  );

  //返回视图
  $("#apply-re-common").click(function(){
    if(index==1){
      loadURL("menu/dashboard",$('#page-content'));
    }else if(todo==1){
      loadURL("menu/toDo",$('#page-content'));
    }else if(remind==1){
      loadURL("menu/remind",$('#page-content'));
    }else if(record==1){
      loadURL("menu/taskRecord?type=1",$('#page-content'));
    }else if(record==2){
      loadURL("menu/taskRecord?type=2",$('#page-content'));
    }else if(draft==1){
      loadURL("menu/draft",$('#page-content'));
    }else{
      returnToHashUrl()
    }
  });


</script>